﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbOrdersExDal
	{
		public DbOrdersExDal()
		{
		}
 		#region Insert
 		public static int Insert(DbOrdersEx dbOrdersEx)
		{	
			string sql = @"Insert Into DbOrdersEx (
					OeOrderSN,
					OePayment,
					OePaySN,
					OePayAmount,
					OePayTime,
					OeStatus,
					OeUserId
				) values('{0}','{1}','{2}',{3},'{4}',{5},{6})";
			sql = string.Format(sql,
					SqlHelper.String(dbOrdersEx.OeOrderSN),
					SqlHelper.String(dbOrdersEx.OePayment),
					SqlHelper.String(dbOrdersEx.OePaySN),
					dbOrdersEx.OePayAmount,
					dbOrdersEx.OePayTime,
					dbOrdersEx.OeStatus,
					dbOrdersEx.OeUserId
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbOrdersEx dbOrdersEx)
		{	
			string sql = @"Update DbOrdersEx set 

					OeOrderSN= '{0}',
					OePayment= '{1}',
					OePaySN= '{2}',
					OePayAmount= {3},
					OePayTime= '{4}',
					OeStatus= {5},
					OeUserId= {6}
				where

					OeId= {7}";
			sql = string.Format(sql,
					SqlHelper.String(dbOrdersEx.OeOrderSN),
					SqlHelper.String(dbOrdersEx.OePayment),
					SqlHelper.String(dbOrdersEx.OePaySN),
					dbOrdersEx.OePayAmount,
					dbOrdersEx.OePayTime,
					dbOrdersEx.OeStatus,
					dbOrdersEx.OeUserId,
					dbOrdersEx.OeId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 oeId)
		{
		
			string sql = @"Delete from DbOrdersEx where 
					OeId= {0}";
			sql = string.Format(sql,
					oeId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbOrdersEx a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbOrdersEx Select(Int32 oeId)
		{
			DbOrdersEx dbOrdersEx = null;
			string sql = @"select a.* from DbOrdersEx a  where
					a.OeId= {0}
";
			sql = string.Format(sql,
					oeId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbOrdersEx = new DbOrdersEx(ds.Tables[0].Rows[0]);					
			return dbOrdersEx;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbOrdersEx a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbOrdersEx a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbOrdersEx a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
